<template>
      <ul>
        <li :style="{opacity}">欢迎学习Vue</li>
            <li>news001<input type="text"></li>
            <li>news002<input type="text"></li>
            <li>news003<input type="text"></li>
      </ul>
</template>

<script>
export default {
  name: 'NewTest',
  data() {
    return {
      opacity: 1,
      // 预先声明 timer
      timer: null
    };
  },
  activated(){
    console.log('News组件被激活了')
        // 设置定时器
        this.timer = setInterval(() => {
      console.log('@');
      this.opacity -= 0.01;
      if (this.opacity <= 0) {
        this.opacity = 1;
      }
    }, 16);
  },
  deactivated(){
    console.log('NewTest组件失活');
    // 确保 timer 存在再清除
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

};
</script>

<style>

</style>